package com.ellfors.module_first.dialog_queue

import android.app.Activity
import android.app.Dialog
import android.view.Gravity
import com.ellfors.common.ext.dp2px
import com.ellfors.module_first.R
import com.ellfors.module_first.databinding.DialogTestBinding

class TestDialog(val activity: Activity) : Dialog(activity, R.style.dialog) {

    private val mBinding by lazy {
        val view = activity.layoutInflater.inflate(R.layout.dialog_test, null)
        DialogTestBinding.bind(view)
    }

    init {
        initDialog()
        initView()
    }

    private fun initDialog() {
        setContentView(mBinding.root)
        window?.attributes?.apply {
            width = 300.dp2px()
            height = 200.dp2px()
            gravity = Gravity.CENTER
        }
    }

    private fun initView() {
        mBinding.btnOk.setOnClickListener {
            dismiss()
        }
    }

    fun setTitle(str: String): TestDialog {
        mBinding.tvTitle.text = str
        return this
    }

    fun setContent(str: String): TestDialog {
        mBinding.tvContent.text = str
        return this
    }

    fun getContent(): String {
        return mBinding.tvContent.text.toString()
    }

}